package com.jifeng.sterilizer.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jifeng.sterilizer.entity.DeviceEntity;
import com.jifeng.sterilizer.entity.UserDeviceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jifeng.sterilizer.entity.UserControllerEntity;
import com.jifeng.sterilizer.service.UserControllerService;
import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.R;



/**
 * 用户中控器表
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-07-26 15:15:14
 */
@RestController
@RequestMapping("sterilizer/usercontroller")
public class UserControllerController {
    @Autowired
    private UserControllerService userControllerService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userControllerService.queryPage(params);

        return R.ok().put("page", page);
    }

    // 获取用户绑定的中控器
    @GetMapping("/listUserControllers")
    public R listUserControllers(@RequestParam Map<String, Object> params){
        R rs= userControllerService.getListUserControllers(params);
        return rs;
    }

    // 获取用户绑定的中控器 微信小程序
    @GetMapping("/wx/listUserControllers")
    public R wxListUserControllers(@RequestParam Map<String, Object> params){
        R rs= userControllerService.getListUserControllers(params);
        return rs;
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserControllerEntity userController = userControllerService.getById(id);

        return R.ok().put("userController", userController);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserControllerEntity userController){
		userControllerService.save(userController);

        return R.ok();
    }

    /**
     * 绑定用户和中控机
     */
    @PostMapping("/addUserController")
    public R addUserController(@RequestBody UserControllerEntity userControllerEntity){
        R rs= userControllerService.addUserController(userControllerEntity);

        return rs;
    }

    /**
     * 解除用户和中控机绑定
     */
    @PutMapping("/removeUserController")
    public R removeUserController(@RequestBody UserControllerEntity userController){
        R rs= userControllerService.removeUserController(userController);

        return rs;
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody UserControllerEntity userController){
		userControllerService.updateById(userController);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userControllerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
